package com.todod.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.todod.entity.QueryEntry;
import com.todod.entity.ResultData;
import com.todod.mapper.SystemValueMapper;
import com.todod.model.SystemValue;
import com.todod.service.ISystemValueService;

/**
 * @author lql
 * @date 2020年12月25日
 */
@RestController
@RequestMapping("/systemValue")
public class SystemValueController extends BaseManageController {

	@Autowired
	public ISystemValueService systemValueService;
	@Autowired
	public SystemValueMapper systemValueMapper;

	/**
	 * 
	 * @param companyId
	 * @param _userId
	 * @param request
	 * @param queryEntry
	 * @return
	 */
	@RequestMapping("/getPage")
	public ResultData getListPage(@RequestBody QueryEntry queryEntry) {

		IPage<SystemValue> page = systemValueService.getListPage(queryEntry);
		return ResultData.success("ok", page);
	}

	/**
	 * 
	 * @param _userId
	 * @param reqSystemValue
	 * @return
	 */
	@PostMapping("/saveData")
	public ResultData saveData(@RequestAttribute Long _userId, @RequestBody SystemValue systemValue) {

		systemValueService.saveData(_userId, systemValue);
		return ResultData.success();
	}

	/**
	 * 
	 * @param _userId
	 * @param reqSystemValue
	 * @return
	 */
	@PostMapping("/editData")
	public ResultData editData(@RequestAttribute Long _userId, @RequestBody SystemValue systemValue) {

		systemValueService.editData(_userId, systemValue);
		return ResultData.success();
	}

	/**
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("/updateState")
	public ResultData updateState(@RequestAttribute Long _userId, Long code, String status) {
		systemValueService.updateState(_userId, code, status);
		return ResultData.success();
	}

	@GetMapping("/getInfo")
	public ResultData getInfo(Long code) {
		if (code == null) {
			return ResultData.error(ResultData.PARAM_ERROR_CODE, "参数错误");
		}
		return ResultData.success("ok", systemValueService.getInfo(code));
	}

}
